package com.cy;

import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test13 {
    public static void main(String[] args) {

        MyTickets2 target =new MyTickets2();

        ExecutorService pool = Executors.newFixedThreadPool(4);
        for(int i =0;i<2;i++){
         //   new Thread(target).start();
            pool.execute(target);
        }

    }
}


class MyTickets2 implements  Runnable{

    int tickets=100;
    Object obj=new Object();
    @Override
    public void run() {
        while(true){
            synchronized(obj){
                if(tickets>0){
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+"~~~"+tickets--);
                }else{
                    break;
                }
            }
        }
    }
}